
function closePayPassword(){

	$(".pay-password-bg").hide()
	$(".pay-pass-bg-wrapper").hide()

}
function showPayPasswordDlg() {
	$(".pay-password-bg").show()
	$(".pay-pass-bg-wrapper").show()
}


function exchange(){
	$(this).attr('disabled', 'disabled');
	var flag = true;
	var msg = "";
	var amount = $('#amount');
	if (amount.val() == '') {
		msg = lang_member_exchange.the_points_need_to_be_redeemed_are_not_null;
		flag = false;
	} else if (Number(amount.val()) > Number(conpon_sum)) {
		msg = lang_member_exchange.the_points_you_need_to_redeem_cannot_be_greater_than_the_points_you_have;
		amount.val(conpon_sum);
		flag = false;
	} else if (Number(amount.val()) < 0) {
		msg = lang_member_exchange.the_points_required_to_be_redeemed_shall_not_be_less_than_0;
		amount.val(0);
		flag = false;
	}
	if (!flag) {
		toast(msg);
		amount.focus();
		$(this).removeAttr('disabled');
		return false;
	}
	api("System.Member.coinExchangeBalance", {'amount': amount.val()}, function (data) {
		var data = data['data'];
		//console.log(data);
		if (data > 0) {
			toast(lang_member_exchange.redeem_successfully);

			setTimeout(function () {
				location.href = __URL(APPMAIN + '/member/index');
			}, 1000);
		} else {
			$(this).removeAttr('disabled');
			toast(data['message']);
		}
	})
}


var is_sub = false;
function calculate(pw) {
	if(is_sub){
		return;
	}
	//alert(pw);
	var params = {pay_password: pw};
	is_sub = true;
	api("System.Member.checkPayPassword", params, function (res) {

		if(res['data'] === 1){
			exchange()
		}else{
			toast("支付密码错误！");
			is_sub = false;
		}
	})
}


$(function () {

	$(".password-div input").on("input",function(e){ //标签为password-div下的input添加oninput事件
		var number = 6;   //定义输入最大值
		var pw = $("input[name = 'password']").val(); //定义pw为name是password的input框的输入值
		var list = $(".password-div ul li");  //定义list是li
		//console.log(pw);
		for(var i = 0; i < number ; i++){    //for循环遍历将·放入li标签
			if(pw[i]){
				$(list[i]).text("·");
			}else{
				$(list[i]).text("");
			};
		};
		if(pw.length == 6){
			console.log('完成支付！')
			calculate(pw);
		}
	});


	$(".password-div ul").click(function(){
		$("input[name = 'password']").val("");
		$("#password").focus();
		$(".password-div ul li").text("");
	});

});